﻿using System;

namespace Example1 {
	internal sealed class SomeType {
		private Int32 m_x = 5;
	}
}


namespace Example2 {
	internal sealed class SomeType {
		private Int32  m_x = 5;
		private String m_s = "Hi there";
		private Double m_d = 3.14159;
		private Byte   m_b;

		// Here are some constructors. 
		public SomeType()         { /* ... */ }
		public SomeType(Int32 x)  { /* ... */ }
		public SomeType(String s) { /* ...; */ m_d = 10; }
	}
}


namespace Example3 {
	internal sealed class SomeType {
		// Do not explicitly initialize the fields here
		private Int32  m_x;
		private String m_s;
		private Double m_d;
		private Byte   m_b;

		// This method MUST be called by all constructors.
		private void SetFieldDefaults() {
			m_x = 5;
			m_s = "Hi there";
			m_d = 3.14159;
			m_b = 0xff;
		}

		// This constructor sets all fields to their default.
		public SomeType() {
			SetFieldDefaults();
		}

		// This constructor sets all fields to their default, then changes m_x.
		public SomeType(Int32 x) {
			SetFieldDefaults();
			m_x = x;
		}

		// This constructor sets all fields to their default, then changes m_s.
		public SomeType(String s) {
			SetFieldDefaults();
			m_s = s;
		}

		// This constructor sets all fields to their default, then changes m_x & m_s.
		public SomeType(Int32 x, String s) {
			SetFieldDefaults();
			m_x = x;
			m_s = s;
		}
	}
}



internal struct SomeValType {
	static SomeValType() {
		Console.WriteLine("This never gets displayed");
	}
	public Int32 m_x;
}

public sealed class Program {
	public static void Main() {
		SomeValType[] a = new SomeValType[10];
		a[0].m_x = 123;
		Console.WriteLine(a[0].m_x);	// Displays 123
	}
}
